<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */
use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

return new class() extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('money_flow_logs', function (Blueprint $table) {
            $table->id();
            $table->enum('type', ['red_packet', 'charge'])->default('red_packet')->comment('类型(red_packet=红包,charge=余额充值)');
            $table->enum('change_type', ['incr', 'decr'])->nullable()->comment('变化类型(incr=增加,decr=减少)');
            $table->unsignedBigInteger('from_id')->default(0)->comment('来源ID');
            $table->unsignedBigInteger('user_id')->default(0)->comment('用户ID');
            $table->integer('money')->default(0)->comment('金额/分');
            $table->unsignedBigInteger('money_before')->default(0)->comment('变化前用户余额/分');
            $table->unsignedBigInteger('money_after')->default(0)->comment('变化后用户余额/分');
            $table->string('remark', 50)->default('')->comment('备注');
            $table->timestamp('created_at')->useCurrent()->comment('创建时间');
            $table->comment('资金流水表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('money_flow_logs');
    }
};
